﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.util.resourceMan;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.shareData;
using Microsoft.Xna.Framework;
using Imaginecup.util.rainEffect;
using Imaginecup.util;
using Imaginecup.sprite;
using Imaginecup.gameState.ending.scene;
using imaginecup.util;

namespace Imaginecup.gameState.ending
{
    public class CloudScene:IScene
    {
        private EntityInfo m_Info;
        private ContentManager m_Content;
        private RainGenerator m_RainGenerator = new RainGenerator();

        private ILoadContent m_LoadContent;
        private ISprite m_CloudSprite;

        private double m_DelayTime = 7;
        private double m_CurrentTime = 0;
        private bool m_bComplete = false;

        public CloudScene()
        {
            m_Info = new EntityInfo(0, 0, 800, 480);
        }

        public void SetLoadEndingScene(scene.ILoadContent content)
        {
           m_LoadContent = content;
        }

        public void LoadEndingScene()
        {
            m_Content = new ContentManager(StateShareData.GetShareData().GetGame().Services);
            m_Content.RootDirectory = "Content";

            ResourceMan.GetResourceMan().SetTextureFrame("Rain", m_Content.Load<Texture2D>("ending\\Rain"));
            m_CloudSprite = m_LoadContent.LoadSprite();
        }

        public void UnloadEndingScene()
        {
            m_LoadContent.UnloadResource();
            m_CloudSprite.Release();
            ResourceMan.GetResourceMan().Release("Rain");
            ParticleMan.GetParticleMan().Release();
            m_Content.Unload();
        }

        public void Update(GameTime gameTime)
        {
            m_CurrentTime += gameTime.ElapsedGameTime.TotalSeconds;
            if (m_CurrentTime > m_DelayTime)
                m_bComplete = true;
            m_RainGenerator.GeneratorRain(gameTime);

            ParticleMan.GetParticleMan().Update(gameTime);
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            m_CloudSprite.Draw(spriteBatch, m_Info);
            ParticleMan.GetParticleMan().Draw(spriteBatch);
        }
             
        public bool IsComplete()
        {
            return m_bComplete;
        }
    }
}
